<?php

$server = new Sxg\Server("0.0.0.0", 9508);

$server->on("connect", function($server, $fd) {
    echo "connection open: ".$fd."\n";
});

$server->on('receive', function ($server, $fd, $reactor_id, $data) {
    echo "reactor_id:{$reactor_id}\r\n";
    $server->send($fd, "Sxg: ".$data);
    if (strncmp("close", $data, 5) == 0) {
        echo "即将关闭客户端连接\r\n";
        $server->close($fd);
    }
});

$server->on('close', function ($server, $fd) {
    echo "connection close: ".$fd."\r\n";
});

$server->start();